package pl.diagnoser.client;

import pl.diagnoser.client.tools.DiagnoserProperties;
import pl.diagnoser.client.tools.LogIn;
import com.google.gwt.user.client.ui.Image;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;

public class ApplicationPanel extends VLayout {
	
	private DiagnoserProperties properties = new DiagnoserProperties();
	
	public ApplicationPanel() {
		this.setWidth("80%");
		this.setStyleName("mainContent");
		this.setHeight("99%");
		this.setLeft("10%");
		
		Image image = new Image("img/banner.jpg");
		image.setWidth("100%");
		
		final SectionStack sectionStack = new SectionStack();  
        sectionStack.setVisibilityMode(VisibilityMode.MUTEX);  
        sectionStack.setWidth100();
        sectionStack.setHeight100();
        
        if(LogIn.getInstance().getUser().getAppId() != null && LogIn.getInstance().getUser().getAppId() > 0) {
	        if(LogIn.getInstance().getUser().getAppId() == LogIn.SEARCH_APP) {
	        	SearchObjects tmp = new SearchObjects();
		        SectionStackSection sSerachObjects = new SectionStackSection("sSerachObjects");  
		        properties.getSectionStackTitle("sSerachObjects", sSerachObjects);
		        sSerachObjects.addItem(tmp);
		        sSerachObjects.setName("sSerachObjects");
		        sSerachObjects.setExpanded(true);
		        sectionStack.addSection(sSerachObjects);
	        }
	        
	        SectionStackSection sObslugaPacjenta = new SectionStackSection("sObslugaPacjenta");  
	        properties.getSectionStackTitle("sObslugaPacjenta", sObslugaPacjenta);
	        sObslugaPacjenta.addItem( new ObjectHandling() );
	        sObslugaPacjenta.setName("sObslugaPacjenta");
	        if(LogIn.getInstance().getUser().getAppId() == LogIn.SEARCH_APP)
	        	sObslugaPacjenta.setExpanded(false);
	        else
	        	sObslugaPacjenta.setExpanded(true);
	        sectionStack.addSection(sObslugaPacjenta);
	        
	        if(LogIn.getInstance().getUser().isAdministrator()) {
	        	if(LogIn.getInstance().getUser().getAppId() != LogIn.SEARCH_APP) {
		        	SectionStackSection sDouczanieSystemu = new SectionStackSection("sDouczanieSystemu");  
			        properties.getSectionStackTitle("sDouczanieSystemu", sDouczanieSystemu);
			        sDouczanieSystemu.addItem(new SystemLearning());
			        sDouczanieSystemu.setName("sDouczanieSystemu");
			        sDouczanieSystemu.setExpanded(false);  
			        sectionStack.addSection(sDouczanieSystemu);
	        	}
		        
		        SectionStackSection sPrzegladanieWiedzy = new SectionStackSection("sPrzegladanieWiedzy"); 
		        properties.getSectionStackTitle("sPrzegladanieWiedzy", sPrzegladanieWiedzy);
		        sPrzegladanieWiedzy.addItem(new PrzegladanieWiedzy());
		        sPrzegladanieWiedzy.setName("sPrzegladanieWiedzy");
		        sPrzegladanieWiedzy.setExpanded(false);
		        sectionStack.addSection(sPrzegladanieWiedzy);
		   
		        SectionStackSection sSystemProperties = new SectionStackSection("sSystemProperties"); 
		        properties.getSectionStackTitle("sSystemProperties", sSystemProperties);
		        sSystemProperties.addItem(new SystemProperties());
		        sSystemProperties.setName("sSystemProperties");
		        sSystemProperties.setExpanded(false);
		        sectionStack.addSection(sSystemProperties);
	        }
        } else {
        	SectionStackSection sSystemProperties = new SectionStackSection("sSystemProperties"); 
	        properties.getSectionStackTitle("sSystemProperties", sSystemProperties);
	        sSystemProperties.addItem(new SystemProperties());
	        sSystemProperties.setName("sSystemProperties");
	        sSystemProperties.setExpanded(true);
	        sectionStack.addSection(sSystemProperties);
        }
        this.addMember(image);
        this.addMember(sectionStack);
	}
}
